//
//  ZSY_StayTableViewCell.m
//  ZSY_BreadTrip
//
//  Created by 张诗宇 on 16/1/5.
//  Copyright © 2016年 张诗宇. All rights reserved.
//

#import "ZSY_StayTableViewCell.h"

@interface ZSY_StayTableViewCell ()

@property (nonatomic, retain) ZSY_BaseImageView *coverImageView;
@property (nonatomic, retain) ZSY_BaseLabel *nameLabel;
@property (nonatomic, retain) ZSY_BaseLabel *ratingLabel;
@property (nonatomic, retain) ZSY_BaseLabel *distanceLabel;
@property (nonatomic, retain) ZSY_BaseLabel *vistedLabel;
@property (nonatomic, retain) ZSY_BaseView *view;
@property (nonatomic, assign) NSInteger count;


@end

@implementation ZSY_StayTableViewCell

- (void)dealloc {
    [_view release];
    [_nearby release];
    [_coverImageView release];
    [_nameLabel release];
    [_distanceLabel release];
    [_ratingLabel release];
    [_vistedLabel release];
    [super dealloc];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)setNearby:(ZSY_NearbyModel *)nearby {
    if (_nearby != nearby) {
        [_nearby release];
        _nearby = [nearby retain];
        
        NSURL *coverUrl = [NSURL URLWithString:_nearby.cover_s];
        [self.coverImageView sd_setImageWithURL:coverUrl placeholderImage:nil];
        
        self.nameLabel.text = _nearby.name;
        self.nameLabel.font = [UIFont boldSystemFontOfSize:16];
        
        
        self.count = _nearby.rating.intValue;
        NSLog(@"%ld", _count);
        if (_count != 0) {
            
            for (int i = 0; i < _count; i++) {
                // 循环铺星星
                ZSY_BaseImageView *rateImageView = [[ZSY_BaseImageView alloc] initWithFrame:CGRectMake(120 + 18 * i, 35, 17, 17)];
                rateImageView.image = nil;
                rateImageView.image = [UIImage imageNamed:@"iconfont-rating - y"];
                [self.view addSubview:rateImageView];
                [rateImageView release];
            }
            
        } else {
            for (int i = 0; i < 5; i++) {
                // 循环铺星星
                ZSY_BaseImageView *rateImageView = [[ZSY_BaseImageView alloc] initWithFrame:CGRectMake(120 + 18 * i, 35, 17, 17)];
                rateImageView.image = nil;
                rateImageView.image = [UIImage imageNamed:@"iconfont-rating - g"];
                [self.view addSubview:rateImageView];
                [rateImageView release];
            }
        }
        self.ratingLabel.text = [NSString stringWithFormat:@"%@ 点评", _nearby.rating_users];
        self.ratingLabel.font = [UIFont systemFontOfSize:11];
        
        self.distanceLabel.text = [NSString stringWithFormat:@"距我 %.0fm", (_nearby.distance).floatValue * 1000];
        self.distanceLabel.font = [UIFont systemFontOfSize:11];
        [self.distanceLabel sizeToFit];
        
        
    }
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}


- (void)createSubviews {
    
//    self.contentView.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:243 / 255.0 blue:233 / 255.0 alpha:1];
    
    
    self.view = [[ZSY_BaseView alloc] initWithFrame:CGRectMake(15, 5, (WIDTH - 30), 120)];
    _view.layer.cornerRadius = 3;
    _view.layer.masksToBounds = YES;
//    _view.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_view];
    
    self.view.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.view.layer.borderWidth = 1;
    self.view.layer.cornerRadius = 5;
    self.view.layer.masksToBounds = YES;
    
    self.coverImageView = [[ZSY_BaseImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
    self.coverImageView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:_coverImageView];
    [_coverImageView release];
    
    self.nameLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(120, 10, WIDTH - 100 - 10 - 10 - 40 - 40, 20)];
    //    self.nameLabel.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:_nameLabel];
    [_nameLabel release];
    
    
    //    for (int i = 0; i < 5; i++) {
    //
    //        ZSY_BaseImageView *rateImageView = [[ZSY_BaseImageView alloc] initWithFrame:CGRectMake(120 + 18 * i, 35, 17, 17)];
    //        rateImageView.image = [UIImage imageNamed:@"iconfont-rating - g"];
    //        [self.view addSubview:rateImageView];
    //        [rateImageView release];
    //    }
    
    
    
    
    
    self.ratingLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(120 + 100, 35, 40, 15)];
    //    self.ratingLabel.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_ratingLabel];
    [_ratingLabel release];
    
    self.distanceLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(120, 99, 60, 10)];
    //    self.distanceLabel.backgroundColor = [UIColor grayColor];
    [self.view addSubview:_distanceLabel];
    [_distanceLabel release];
    
    [_view release];
    
}



@end
